/**
 * Created by seeker910 on 2018/3/6.
 *
 * 楼栋信息+房屋信息列表
 */
Rsd.define('Rsd.Faith.dialogs.InfoLouDongDialog', {
    extend: 'Rsd.view.MajorSubDialog',
    requires: [
        'Rsd.controlEx.MajorSubViewer',
        'Rsd.Faith.stores.ListStore'
    ],
    title:'小区详情',
    sub: {
        fk:'XiaoQuBianHao',
        toolBar:{
            xtype:'grid-tool-bar-simple',
            newButtons:[
                {xtype:'label',text:'★ 下方列表为该小区楼栋列表，信息来自房屋信息👇'}
            ]},
        columns:[
            {
                "text": "序号",
                "xtype": "index",
                "width": 40,
                "index": 0,
                "deep": 1
            },
            {
                "name": "LouDongHao",
                "dataIndex": "LouDongHao",
                "sortable": false,
                "text": "楼栋号",
                "index": 23,
                "exist": true,
                "xtype": "string",
                align:'center',
                "width": 50,
                "nobr": true,
                "deep": 1
            },
            {
                "name": "SuoShuQi",
                "dataIndex": "SuoShuQi",
                "sortable": false,
                "text": "所属期",
                "index": 24,
                "exist": true,
                "xtype": "string",
                align:'center',
                "width": 50,
                "nobr": true,
                "deep": 1
            },
            {
                "name": "QiChuJinE_ZZ",
                "dataIndex": "QiChuJinE_ZZ",
                "sortable": false,
                "text": "期初(住房)",
                "index": 26,
                "exist": true,
                "xtype": "number",
                "width": 100,
                "precision": 2,
                "deep": 1
            },
            {
                "name": "JiaoCunJinE_ZZ",
                "dataIndex": "JiaoCunJinE_ZZ",
                "sortable": false,
                "text": "缴存(住房)",
                "index": 28,
                "exist": true,
                "xtype": "number",
                "total":true,
                "width": 100,
                "precision": 2,
                "deep": 1
            },
            {
                "name": "ShiYongJinE_ZZ",
                "dataIndex": "ShiYongJinE_ZZ",
                "sortable": false,
                "text": "使用(住房)",
                "index": 32,
                "exist": true,
                "xtype": "number",
                "total":true,
                "width": 100,
                "precision": 2,
                "deep": 1
            },
            {
                "name": "YuE_ZZ",
                "dataIndex": "YuE_ZZ",
                "sortable": false,
                "text": "余额(住房)",
                "index": 40,
                "exist": true,
                "xtype": "number",
                "total":true,
                "width": 100,
                "precision": 2,
                "deep": 1
            },
            {
                "name": "ShouYiJinE_ZZ",
                "dataIndex": "ShouYiJinE_ZZ",
                "sortable": false,
                "text": "分户利息合计",
                "index": 30,
                "exist": true,
                "xtype": "number",
                "total":true,
                "width": 100,
                "precision": 2,
                "deep": 1
            },
            /*{
                "name": "QiChuJinE_DT",
                "dataIndex": "QiChuJinE_DT",
                "sortable": false,
                "text": "期初(电梯/消防)",
                "index": 27,
                "exist": true,
                "xtype": "number",
                "width": 100,
                "precision": 0,
                "deep": 1
            },
            {
                "name": "JiaoCunJinE_DT",
                "dataIndex": "JiaoCunJinE_DT",
                "sortable": false,
                "text": "缴存(电梯/消防)",
                "index": 34,
                "exist": true,
                "xtype": "number",
                "width": 100,
                "precision": 2,
                "deep": 1
            },
            {
                "name": "ShouYiJinE_DT",
                "dataIndex": "ShouYiJinE_DT",
                "sortable": false,
                "text": "增值(电梯/消防)",
                "index": 36,
                "exist": true,
                "xtype": "number",
                "width": 100,
                "precision": 2,
                "deep": 1
            },
            {
                "name": "ShiYongJinE_DT",
                "dataIndex": "ShiYongJinE_DT",
                "sortable": false,
                "text": "使用(电梯/消防)",
                "index": 38,
                "exist": true,
                "xtype": "number",
                "width": 100,
                "precision": 2,
                "deep": 1
            },
            {
                "name": "YuE_DT",
                "dataIndex": "YuE_DT",
                "sortable": false,
                "text": "余额(电梯/消防)",
                "index": 42,
                "exist": true,
                "xtype": "number",
                "width": 100,
                "precision": 3,
                "deep": 1
            },*/
            {
                "name": "ZhuangTai",
                "dataIndex": "ZhuangTai",
                "sortable": false,
                "text": "状态",
                "index": 44,
                "exist": true,
                "xtype": "enum",
                "enum": {
                    "name": "Rsd.Faith.Core.ZhuangMuZhuangTai",
                    "items": [
                        {
                            "code": "null",
                            "text": "未设置",
                            "value": -1,
                            color:'grey'
                        },
                        {
                            "code": "JZZ",
                            "text": "记账中",
                            "value": 0
                        },
                        {
                            "code": "YHS",
                            "text": "已扎帐",
                            "value": 1
                        }
                    ]
                },
                "width": 70,
                "nobr": true,
                "deep": 1
            },
            {
                "name": "Remark",
                "dataIndex": "Remark",
                "sortable": false,
                "text": "备注",
                "index": 50,
                "exist": true,
                "xtype": "string",
                "width": 50,
                "nobr": true,
                "deep": 1
            }
        ]
    },
    major: {
        modelType:'Rsd.Faith.Models.InfoXiaoQuWuYeBiaoModel',
        height:170,
        legend: '基本信息',
        key:'BianHao',
        "fields": [

            {
                "name": "BianHao",
                "label": {
                    "width": 80,
                    "content": "编号"
                },
                "dataIndex": "BianHao",
                "index": 1,
                "exist": true,
                "xtype": "text",
                width:350,
                "length": 20
            },
            {
                "name": "MingCheng",
                "label": {
                    "width": 80,
                    "content": "名称"
                },
                "dataIndex": "MingCheng",
                "index": 2,
                "exist": true,
                "xtype": "text",
                width:350,
                "length": 100
            },
            {
                "name": "ZongDongShu",
                "label": {
                    "width": 80,
                    "content": "总栋数"
                },
                "dataIndex": "ZongDongShu",
                "index": 3,
                "exist": true,
                "xtype": "text",
                width:350,
                "length": 10
            },
            {
                "name": "ZongTaoShu",
                "label": {
                    "width": 80,
                    "content": "总套数"
                },
                "dataIndex": "ZongTaoShu",
                "index": 4,
                "exist": true,
                "xtype": "text",
                width:350,
                "length": 10
            },
            {
                "name": "JianZhuMianJi",
                "label": {
                    "width": 80,
                    "content": "建筑面积"
                },
                "dataIndex": "JianZhuMianJi",
                "index": 5,
                "exist": true,
                "xtype": "number",
                width:350,
                "precision": 2
            },
            {
                "name": "JianChengRiQi",
                "label": {
                    "width": 80,
                    "content": "建成日期"
                },
                "dataIndex": "JianChengRiQi",
                "index": 6,
                "exist": true,
                "xtype": "date",
                width:350,
                "formatString": "yyyy-MM-dd"
            },
            {
                "name": "KaiFaShangBianHao",
                "label": {
                    "width": 80,
                    "content": "开发商编号"
                },
                "dataIndex": "KaiFaShangBianHao",
                "index": 7,
                "exist": true,
                "xtype": "text",
                width:350,
                "length": 20
            },
            {
                "name": "WuYeGongSiBianHao",
                "label": {
                    "width": 80,
                    "content": "物业公司编号"
                },
                "dataIndex": "WuYeGongSiBianHao",
                "index": 8,
                "exist": true,
                "xtype": "text",
                width:350,
                "length": 20
            },
            {
                "name": "YeWeiHuiBianHao",
                "label": {
                    "width": 80,
                    "content": "业委会编号"
                },
                "dataIndex": "YeWeiHuiBianHao",
                "index": 9,
                "exist": true,
                "xtype": "text",
                width:350,
                "length": 20
            },
            {
                "name": "DiZhi",
                "label": {
                    "width": 80,
                    "content": "地址"
                },
                "dataIndex": "DiZhi",
                "index": 10,
                "exist": true,
                "xtype": "text",
                width:350,
                "length": 200
            },
            {
                "name": "SuoShuDiQu",
                "label": {
                    "width": 80,
                    "content": "所属地区"
                },
                "dataIndex": "SuoShuDiQu",
                "index": 11,
                "exist": true,
                "xtype": "text",
                width:350,
                "length": 20
            },
            {
                "name": "Remark",
                "label": {
                    "width": 80,
                    "content": "备注"
                },
                "dataIndex": "Remark",
                "index": 200,
                "exist": true,
                "xtype": "text",
                width:350,
                "length": 100
            }
        ]

    },
    width: 1200,
    height: 600,
    showClose:true,
    /*
     *
     * */
    constructor :function constructor(config) {
        config = config || {};
        this.apply(config);

    },
    format_loudonghao:function format_loudonghao(row) {

        return [ Rsd.text(row['LouDongHao']||'-')]
    },
    format_tpl:function(row)
    {
        if(Rsd.isEmpty(row['LouDongHao']))
        {
            return [];
        }
        var me = this;
        //report.exportexcel
        var s = Rsd.app.getService('report.exportexcel');

        var  btnExport = document.createElement('a');
        btnExport.href=s.server.url + '?xiaoqubianhao='+row['XiaoQuBianHao']+'&loudonghao='+row['LouDongHao'] + '&___key='+Rsd.app.token;
        btnExport.innerHTML = '发票导出';

        $(btnExport).click (function(){
            me.showLoading('正在下载...');
            setTimeout(function () {
                me.closeLoading();
            },2000);
        });


        return [btnExport]
    },
    load:function load(row) {


        var me = this;
        var _row = row||this.data;
        if( Rsd.isString(_row))//如果是小区编号
        {
            var _bian_hao = _row;
            Rsd.app.getService('info.GetXiaoQuAndLouDongList').requestJson({xiaoqubianhao:_bian_hao},function(data ){
                //console.log(data);
                me.callParentFn('load',[data.data.XiaoQu,data.data.LouDongList]);

            });
        }else//如果是小区对象
        {
            var _bian_hao = _row['BianHao'];

            Rsd.app.getService('info.getloudonglist').requestJson({xiaoqubianhao:_bian_hao},function(data ){

                me.callParentFn('load',[_row,data.data]);

            });

        }

        //
    }
});